package com.plantpoint.config;

import com.plantpoint.interceptor.TokenInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

@Configuration
@Component
public class InterceptorConfig extends WebMvcConfigurationSupport {
    //为方便测试，有需要可以注释掉以下的配置
    private final TokenInterceptor tokenInterceptor;


    public InterceptorConfig(TokenInterceptor tokenInterceptor) {
        this.tokenInterceptor = tokenInterceptor;
    }

    @Override
    protected void addInterceptors(InterceptorRegistry registry) {
        //拦截所有目录，除了通向login和register以及验证码的接口
        registry.addInterceptor(tokenInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns("/**/**/login/**", "/**/**/register/**", "/**/**/verifyCode/**","/**/**/plant/**","/**/pushOneUser/**")
                .excludePathPatterns("/*/*.html", "/*/*.js", "/*/*.css");
    }
}